import { ChangeDetectorRef, Component, OnInit, ViewChild } from '@angular/core';
import { ColumnType, SPage, TablePageComponent } from '@shared/components/table-page/table-page.component';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import { DicEditComponent } from '../dic-edit/dic-edit.component';
import { ApiService } from '@core/services/api';
import { _HttpClient } from '@delon/theme';
import { UtilService } from '@core/services/util.service';

@Component({
  selector: 'app-dic-list',
  templateUrl: './dic-list.component.html',
  styles: []
})
export class DicListComponent implements OnInit {
  @ViewChild('st', {static: false})st: TablePageComponent;
  show:boolean = true
  config: SPage = {
    columns: [
      {
        index: 'categoryCode',
        title: '收费类目',
        type:ColumnType.tag,
        fFn(item, columu) {
          var arr = item.categoryVoList
          var list=[]
          for(let item of arr){
            list.push("&nbsp;&nbsp;&nbsp;&nbsp;"+item.name)
          }
          return list.join(",")
        },
        // filter: {
        //   type: 'select',
        //   mode:'multiple',
        //   placeholder:"请选择收费类目",
        //   items:[]
        // }
      },
      // {
      //   index: 'shineFieldName',
      //   title: '是否缴费',
      //   filter: {
      //     type: 'select',
      //     placeholder:'请选择是否缴费',
      //     items:[
      //       {label:'不缴费',value:'0'},
      //       {label:'缴费',value:'1'}
      //     ]
      //   }
      // },
      {
        index:"userName",
        title:"用户",
        filter:{
          type:"string",
          placeholder:"用户"
        }
      },
      {
        index: 'clientType',
        title: '缴费端',
        type: ColumnType.tag,
        tag:{
          0:{text:'PC端+小程序端'},
          1:{text:'PC端'},
          2:{text:'小程序端'},
        },
        filter: {
          type: 'select',
          placeholder:'请选择缴费端',
          items:[
            {label:'PC端+小程序端',value:0},
            {label:'PC端',value:1},
            {label:'小程序端',value:2}
          ]
        }
      },
      {
        index: '',
        title: '操作',
        width:240,
        fixed:'right',
        buttons:[
          {
            text:'编辑',
            click:(_record)=>{
              this.editDic(1, _record);
            }
          },
          {
            text:'删除',
            click:(_record)=>{
              this.deleteDic(_record);
            }
          },
        ]
      },
    ],
    reqUrl: "/system/user/fee/findPageList",
  };
  selectedData: any[];
  editDic(type: 0 | 1 = 0, _param?: any): void {
    const mymodal = this.modal.create({
      nzTitle: type === 0 ? '新增' : '编辑',
      nzContent: DicEditComponent,
      nzWidth: 800,
      nzComponentParams: {
        type,
        _param
      },
      nzFooter: null
    })
    mymodal.afterClose.subscribe(res => {
      if (res === 'ok') {
        this.st.reload();
      }
    })
  }
  selectChange(e): void {
    this.selectedData = e;
  }
  operate(e): void {
    console.log(e);
    if (e.title === '编辑') {
      this.editDic(1 , e.data)
    }
  }
  deleteDic(data): void {
    this.modal.confirm({
      nzTitle: '确定删除?',
      nzOnOk: () => {
        this.http.get("/system/user/fee/deleteByid?id="+data.id).subscribe(res => {
          if (res.status === '200') {
            this.msg.success('删除成功')
            this.st.reload()
          }else{
            this.msg.error(res.message)
          }
        })
      }
    })
  }
   //获取收费类目列表
   getCategory(){
    this.http.request<any>("get", "/system/user/fee/getCategoryList", {}).subscribe(res => {
      if (res.status === '201' || res.status === '200') {
        this.config.columns[0].filter.items= res.data.map(item => {
          return {
            label: item.name,
            value: item.code
          }
        });
        this.show = true
      } else {
        this.msg.error(res.message)
      }
    })
  }
  constructor(
    private modal: NzModalService,
    private msg: NzMessageService,
    private api: ApiService,
    private http: _HttpClient,
    private util: UtilService,
    private cdr: ChangeDetectorRef
  ) { }

  ngOnInit() {
    
  }
  ngAfterViewInit(){
  }

}
